<!--
 * @Author: zqx me_zqx@163.com
 * @Date: 2025-07-11 20:01:53
 * @LastEditors: zqx me_zqx@163.com
 * @LastEditTime: 2025-07-16 14:52:31
 * @FilePath: /XMate-h5/src/views/minutes/components/analysis/index.vue
 * @Description: 
 * 
 * Copyright (c) 2025 by ${git_name_email}, All Rights Reserved. 
-->
<template>
  <div class="flex flex-col bg-white flex-auto">
    <TabBar v-model:active="active" :tabs="cp_tabs" />
    <div class="flex flex-col flex-auto bg-white" v-ai-tip>
      <AnalysisOverview
        v-if="currentTab.type === AnalysisType.AnalysisOverviewType"
        @update:active="(index) => (active = index)"
      />
      <CustomerAttitude v-if="currentTab.type === AnalysisType.CustomerAttitudeType" />
      <CompetitionSituation
        v-if="currentTab.type === AnalysisType.CompetitionSituationType"
      />
      <AnalysisTodo v-if="currentTab.type === AnalysisType.AnalysisTodoType" />
      <AnalysisRisk v-if="currentTab.type === AnalysisType.AnalysisRiskType" />
      <AnalysisCommon
        v-if="currentTab.type === AnalysisType.AnalysisCommonType"
        :content="currentTab?.content || ''"
      />
    </div>
  </div>
</template>

<script setup lang="ts">
import TabBar from "@/components/CustomTabBar.vue";
import { ref, computed, ComputedRef } from "vue";
import { useMinutesStore } from "@/store";
import { ReportData, SalesAnalysisReport } from "@/types";
import AnalysisOverview from "./AnalysisOverview.vue";
import CustomerAttitude from "./CustomerAttitude.vue";
import CompetitionSituation from "./CompetitionSituation.vue";
import AnalysisTodo from "./AnalysisTodo.vue";
import AnalysisRisk from "./AnalysisRisk.vue";
import AnalysisCommon from "./AnalysisCommon.vue";

enum AnalysisType {
  AnalysisCommonType = 0,
  // 系统预设不要更改
  AnalysisOverviewType = 100,
  CustomerAttitudeType = 101,
  CompetitionSituationType = 102,
  AnalysisTodoType = 103,
  AnalysisRiskType = 104,
}

interface AnalysisTab {
  title: string;
  type: AnalysisType;
  content: string;
}

function mapSystemIdToType(systemId: number): AnalysisType {
  return systemId;
}

const store = useMinutesStore();
const active = ref(0);

const cp_tabs: ComputedRef<AnalysisTab[]> = computed(() => {
  const report: ReportData = store.report;
  const { salesAnalysisReports } = report;
  return salesAnalysisReports.map((v: SalesAnalysisReport) => {
    let title = v.name;
    return {
      title,
      type: mapSystemIdToType(v.systemId),
      content: v.report,
    };
  });
});

const currentTab: AnalysisTab = computed(() => cp_tabs.value[active.value]);
</script>

<style scoped lang="less"></style>
